﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CategoryList.ascx.cs"
    Inherits="HUGATE.Item.Controls.Category.CategoryList" %>
<%@ Register Src="CategoryEdit.ascx" TagName="CategoryEdit" TagPrefix="uc1" %>
<%@ Register assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI" tagprefix="asp" %>
<table border="0" cellpadding="0" cellspacing="0" style="width: 100%">
    <tbody>
        <tr>
            <td style="width: 120px">
                Chọn ngành hàng:
            </td>
            <td style="width: 210px">
                <asp:UpdatePanel ID="udpInside" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <telerik:RadComboBox ID="rcbCategory" runat="server">
                        <ItemTemplate>
                        <div id="div1">
                            <telerik:RadTreeView ID="rtvCategoryInside" runat="server">
                            </telerik:RadTreeView>
                        </div>
                        </ItemTemplate>
                        <Items>
                        <telerik:RadComboBoxItem Text="" />
                        </Items>
                        </telerik:RadComboBox>

                        
                    </ContentTemplate>
                </asp:UpdatePanel>
            </td>
            <td>
                <asp:Button ID="btnSearch" runat="server" CssClass="Control_Button1" OnClick="btnSearch_Click" />
                <asp:Button ID="btnReturn" runat="server" CssClass="Control_Button1" UseSubmitBehavior="False" />
            </td>
            <td align="left">
                <asp:UpdateProgress ID="UpdateProgress2" runat="server" DisplayAfter="10">
                    <ProgressTemplate>
                        <img alt="" src='<%=CoreLibs.Globals.ApplicationVRoot() +"/App_Themes/Default/Images/System/ajaxload.gif" %>' />
                    </ProgressTemplate>
                </asp:UpdateProgress>
            </td>
        </tr>
    </tbody>
</table>
<script type="text/javascript">
    function nodeClicking(sender, args) {
        var comboBox = $find("<%=rcbCategory.ClientID %>");

        var node = args.get_node()

        comboBox.set_text(node.get_text());

        comboBox.trackChanges();
        comboBox.get_items().getItem(0).set_text(node.get_text());
        comboBox.commitChanges();

        comboBox.hideDropDown();

        // Call comboBox.attachDropDown if:
        // 1) The RadComboBox is inside an AJAX panel.
        // 2) The RadTreeView has a server-side event handler for the NodeClick event, i.e. it initiates a postback when clicking on a Node.
        // Otherwise the AJAX postback becomes a normal postback regardless of the outer AJAX panel.

        //comboBox.attachDropDown();
    }
    function StopPropagation(e) {
        if (!e) {
            e = window.event;
        }

        e.cancelBubble = true;
    }

    function OnClientDropDownOpenedHandler(sender, eventArgs) {
        var tree = sender.get_items().getItem(0).findControl("rtvCategoryInside");
        var selectedNode = tree.get_selectedNode();
        if (selectedNode) {
            selectedNode.scrollIntoView();
        }
    }
    var div1 = document.getElementById("div1");
    div1.onclick = StopPropagation;
</script>
<table>
<tr>
<td>
<telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="DeleteButton">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="rtvCategory" LoadingPanelID="ralpTreeview" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
   <telerik:RadAjaxLoadingPanel ID="ralpTreeview" Runat="server" Skin="Default"/>
        <telerik:RadTreeView ID="rtvCategory" runat="server" 
            EnableDragAndDrop="True">
        </telerik:RadTreeView>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Xin Hãy Chọn Mục Hàng Muốn Xóa"
ControlToValidate="rtvCategory" Display="Dynamic" ValidationGroup="Selecction" ></asp:RequiredFieldValidator>
</td>
<td>
<asp:Button ID="btnAddNew" runat="server" CssClass="Control_Button1" OnClick="btnAddNew_Click" Width="100px" ValidationGroup="Selecction"/></br>
    <br />
<asp:Button ID="btnDelete" runat="server" CssClass="Control_Button1" 
    onclick="btnDelete_Click" ValidationGroup="Selecction" Width="100px"/>
    <br />
    <br />
<asp:Button ID="btnEdit" runat="server" CssClass="Control_Button1" 
        ValidationGroup="Selecction" Width="100px" onclick="btnEdit_Click"/>
</td>
</tr>
</table>
  
<asp:UpdatePanel ID="udpList" runat="server" UpdateMode="Conditional" Visible="false">
    <ContentTemplate>
        <asp:GridView ID="grvObject" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            CssClass="Gridview" DataKeyNames="CategoryID" OnPageIndexChanging="grvObject_PageIndexChanging"
            OnSelectedIndexChanged="grvObject_SelectedIndexChanged" PageSize="20" Width="100%"
            OnRowDataBound="grvObject_RowDataBound">
            <EmptyDataTemplate>
                <center>
                    <%#HUGATE.Utility.ResxManager.GetString("BUTEmptyData")%>
                </center>
            </EmptyDataTemplate>
            <Columns>
                <asp:BoundField DataField="RefCategoryID">
                    <ItemStyle CssClass="Gridview_Column_ID" />
                </asp:BoundField>
                <asp:BoundField DataField="CategoryName">
                    <ItemStyle Width="200px" />
                </asp:BoundField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <%#Eval("Description").ToString().Replace("\n","<BR />" )%>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Level">
                    <ItemStyle Width="200px" HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:BoundField DataField="NodeTree">
                    <ItemStyle Width="200px" HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:TemplateField ShowHeader="False">
                    <ItemStyle />
                    <ItemTemplate>
                        <asp:TreeView runat="server" ID="tvChildCategory" ShowLines="True" CollapseImageUrl="~/App_Themes/Default/Images/TreeLineImages/Collapse.gif"
                            ExpandImageUrl="~/App_Themes/Default/Images/TreeLineImages/Expand.gif" Style="float: left">
                        </asp:TreeView>
                        <asp:Label ID="lbCategoryID" runat="server" Text='<%# Eval("CategoryID") %>' Visible="False"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CheckBoxField DataField="IsDefault">
                    <ItemStyle HorizontalAlign="Center" Width="70px" />
                </asp:CheckBoxField>
                <asp:CheckBoxField DataField="IsActived">
                    <ItemStyle HorizontalAlign="Center" Width="70px" />
                </asp:CheckBoxField>
                <asp:TemplateField ShowHeader="False">
                    <ItemStyle CssClass="Update" />
                    <ItemTemplate>
                        <asp:LinkButton ID="lbtEdit" runat="server" CommandArgument='<%#Eval("CategoryID")%>'
                            CommandName="Select" CssClass="UpdateBtn" ToolTip='<%#ResxManager.GetString("Btn_Update")%>'
                            OnClick="lbtEdit_Click">
                        </asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemStyle CssClass="Delete" />
                    <ItemTemplate>
                        <asp:LinkButton ID="lbtDelete" runat="server" CommandArgument='<%#Eval("CategoryID")%>'
                            CssClass="DeleteBtn" OnClick="imgDelete_Click" OnClientClick='<%# "return confirm(\"" + string.Format(ResxManager.GetString("DeleteConfirm"), "") + "\");" %>'
                            ToolTip='<%#ResxManager.GetString("Delete")%>'>
                        </asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <RowStyle CssClass="Row" />
            <PagerStyle CssClass="Pager" />
            <HeaderStyle CssClass="Header" />
            <AlternatingRowStyle CssClass="RowAlt" />
        </asp:GridView>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="udpEdit" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Panel ID="pnlUpdate" runat="server" CssClass="Popup_Table" Style="display: none;
            width: 450px">
            <div class="Popup_Title">
                <table border="0" cellpadding="0" cellspacing="0" class="Popup_Title" style="width: 100%">
                    <tbody>
                        <tr>
                            <td>
                                <strong>
                                    <asp:Label ID="lblTitle" runat="server"></asp:Label>
                                </strong>
                            </td>
                            <td align="center" style="padding-right: 2px; width: 20px">
                                <div class="Popup_BtClose" style="width: 17px; height: 17px; text-align: center">
                                    <asp:LinkButton ID="lnkClose" runat="server" CssClass="Popup_BtClose" Height="17px"
                                        Width="17px" OnClick="lnkClose_Click"></asp:LinkButton>
                                </div>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="Popup_Content">
                <uc1:CategoryEdit id="ctrlCategoryEdit" runat="server">
                </uc1:CategoryEdit>
            </div>
            <div id="divControl" runat="server" style="display: none">
            </div>
            <ajaxToolkit:ModalPopupExtender ID="mpeUpdate" runat="server" BackgroundCssClass="ModalPopupBackground"
                PopupControlID="pnlUpdate" TargetControlID="divControl">
            </ajaxToolkit:ModalPopupExtender>
        </asp:Panel>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnAddNew" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>
